package com.sfzd5.UI;

import javax.swing.*;
import java.util.*;

public class SortListModel<E> extends AbstractListModel<E> {

    LinkedList<E> model;

    public SortListModel() {
        model = new LinkedList<>();
    }

    public void sort(Comparator<E> comparator){
        Collections.sort(model,comparator);
    }

    public void fireContentsChanged(){
        fireContentsChanged(this, 0, getSize());
    }

    public int getSize() {
        return model.size();
    }

    public E getElementAt(int index) {
        return model.get(index);
    }

    public void add(E element) {
        model.add(element);
    }

    public void addAll(List<E> elements) {
        model.addAll(elements);
    }

    public void clear() {
        model.clear();
    }

    public boolean contains(Object element) {
        return model.contains(element);
    }

    public E firstElement() {
        return model.getFirst();
    }

    public Iterator<E> iterator() {
        return model.iterator();
    }

    public Object lastElement() {
        return model.getLast();
    }

    public boolean removeElement(Object element) {
        boolean removed = model.remove(element);
        return removed;
    }
}